package art_of_java_concurrent_programming.thread_local;

/**
 * https://my.oschina.net/ironwill/blog/1612455
 */
public class Performance {
    static ThreadLocal<Long> threadLocal = new ThreadLocal<>();

    public static final void begin() {
        long beginTimeMillis = System.currentTimeMillis();
        threadLocal.set(beginTimeMillis);
    }

    public static final long end() {
        return System.currentTimeMillis() - threadLocal.get();
    }

    public static void main(String[] args) {

        Thread t1 = new Thread() {
            @Override
            public void run() {
                Performance.begin();
                // doSomething();
                long time = Performance.end();
                System.out.println(time);
            }
        };
        Thread t2 = new Thread() {
            @Override
            public void run() {
                Performance.begin();
                // doSomething();
                long time = Performance.end();
                System.out.println(time);
            }
        };
        t1.start();
        t2.start();
    }

}